home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / catD / pciio_pio.z / pciio_pio
Encoding:
Text File  |  2001-04-17  |  20.1 KB  |  397 lines

  1.  
  2.  
  3.  
  4. ppppcccciiiiiiiioooo____ppppiiiioooo((((DDDD3333))))                                                    ppppcccciiiiiiiioooo____ppppiiiioooo((((DDDD3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      pciio_pio: pciio_pio_addr, pciio_piotrans_addr, pciio_piomap_alloc,
  10.      pciio_piomap_addr, pciio_piomap_done, pciio_piomap_free,
  11.      pciio_piospace_alloc, pciio_piospace_free - programmed I/O to PCI bus
  12.  
  13. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  14.      ####iiiinnnncccclllluuuuddddeeee <<<<ssssyyyyssss////PPPPCCCCIIII////ppppcccciiiiiiiioooo....hhhh>>>>
  15.  
  16.      ccccaaaaddddddddrrrr____tttt
  17.      ppppcccciiiiiiiioooo____ppppiiiioooo____aaaaddddddddrrrr((((
  18.           vvvveeeerrrrtttteeeexxxx____hhhhddddllll____tttt _v_h_d_l,,,,
  19.           ddddeeeevvvviiiicccceeee____ddddeeeesssscccc____tttt _d_e_s_c,,,,
  20.           ppppcccciiiiiiiioooo____ssssppppaaaacccceeee____tttt _s_p_a_c_e,,,,
  21.           iiiiooooppppaaaaddddddddrrrr____tttt _a_d_d_r,,,,
  22.           ssssiiiizzzzeeee____tttt _s_i_z_e,,,,
  23.           ppppcccciiiiiiiioooo____ppppiiiioooommmmaaaapppp____tttt ****_m_a_p_p,,,,
  24.           uuuunnnnssssiiiiggggnnnneeeedddd _f_l_a_g_s))))
  25.  
  26.      ccccaaaaddddddddrrrr____tttt
  27.      ppppcccciiiiiiiioooo____ppppiiiioooottttrrrraaaannnnssss____aaaaddddddddrrrr((((
  28.           vvvveeeerrrrtttteeeexxxx____hhhhddddllll____tttt _v_h_d_l,,,,
  29.           ddddeeeevvvviiiicccceeee____ddddeeeesssscccc____tttt _d_e_s_c,,,,
  30.           ppppcccciiiiiiiioooo____ssssppppaaaacccceeee____tttt _s_p_a_c_e,,,,
  31.           iiiiooooppppaaaaddddddddrrrr____tttt _a_d_d_r,,,,
  32.           ssssiiiizzzzeeee____tttt _s_i_z_e,,,,
  33.           uuuunnnnssssiiiiggggnnnneeeedddd _f_l_a_g_s))))
  34.  
  35.      ppppcccciiiiiiiioooo____ppppiiiioooommmmaaaapppp____tttt
  36.      ppppcccciiiiiiiioooo____ppppiiiioooommmmaaaapppp____aaaalllllllloooocccc((((
  37.           vvvveeeerrrrtttteeeexxxx____hhhhddddllll____tttt _v_h_d_l,,,,
  38.           ddddeeeevvvviiiicccceeee____ddddeeeesssscccc____tttt _d_e_s_c,,,,
  39.           ppppcccciiiiiiiioooo____ssssppppaaaacccceeee____tttt _s_p_a_c_e,,,,
  40.           iiiiooooppppaaaaddddddddrrrr____tttt _a_d_d_r,,,,
  41.           ssssiiiizzzzeeee____tttt _s_i_z_e,,,,
  42.           ssssiiiizzzzeeee____tttt _m_a_x,,,,
  43.           uuuunnnnssssiiiiggggnnnneeeedddd _f_l_a_g_s))))
  44.  
  45.      ccccaaaaddddddddrrrr____tttt
  46.      ppppcccciiiiiiiioooo____ppppiiiioooommmmaaaapppp____aaaaddddddddrrrr((((
  47.           ppppcccciiiiiiiioooo____ppppiiiioooommmmaaaapppp____tttt _m_a_p,,,,
  48.           iiiiooooppppaaaaddddddddrrrr____tttt _a_d_d_r,,,,
  49.           ssssiiiizzzzeeee____tttt _s_i_z_e))));;;;
  50.  
  51.      vvvvooooiiiidddd
  52.      ppppcccciiiiiiiioooo____ppppiiiioooommmmaaaapppp____ddddoooonnnneeee((((ppppcccciiiiiiiioooo____ppppiiiioooommmmaaaapppp____tttt _m_a_p))))
  53.  
  54.      vvvvooooiiiidddd
  55.      ppppcccciiiiiiiioooo____ppppiiiioooommmmaaaapppp____ffffrrrreeeeeeee((((ppppcccciiiiiiiioooo____ppppiiiioooommmmaaaapppp____tttt _m_a_p))))
  56.  
  57.      iiiiooooppppaaaaddddddddrrrr____tttt
  58.      ppppcccciiiiiiiioooo____ppppiiiioooossssppppaaaacccceeee____aaaalllllllloooocccc((((
  59.           vvvveeeerrrrtttteeeexxxx____hhhhddddllll____tttt _v_h_d_l,,,,
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. ppppcccciiiiiiiioooo____ppppiiiioooo((((DDDD3333))))                                                    ppppcccciiiiiiiioooo____ppppiiiioooo((((DDDD3333))))
  71.  
  72.  
  73.  
  74.          ddddeeeevvvviiiicccceeee____ddddeeeesssscccc____tttt _d_e_s_c,,,,
  75.           ppppcccciiiiiiiioooo____ssssppppaaaacccceeee____tttt _s_p_a_c_e,,,,
  76.           ssssiiiizzzzeeee____tttt _s_i_z_e,,,,
  77.           ssssiiiizzzzeeee____tttt _a_l_i_g_n))))
  78.  
  79.      vvvvooooiiiidddd
  80.      ppppcccciiiiiiiioooo____ppppiiiioooossssppppaaaacccceeee____ffffrrrreeeeeeee((((
  81.           vvvveeeerrrrtttteeeexxxx____hhhhddddllll____tttt _v_h_d_l,,,,
  82.           ppppcccciiiiiiiioooo____ssssppppaaaacccceeee____tttt _s_p_a_c_e,,,,
  83.           iiiiooooppppaaaaddddddddrrrr____tttt _a_d_d_r,,,,
  84.           ssssiiiizzzzeeee____tttt _s_i_z_e))))
  85.  
  86.    AAAArrrrgggguuuummmmeeeennnnttttssss
  87.      _a_d_d_r    The offset within the given _s_p_a_c_e.
  88.  
  89.      _a_l_i_g_n   A desired alignment in PCI address space.
  90.  
  91.      _d_e_s_c    A device descriptor, usually zero.
  92.  
  93.      _f_l_a_g_s   Flags describing the use of the PIO map.
  94.  
  95.      _m_a_x     The maximum size within _s_p_a_c_e to be mapped at any one time.
  96.  
  97.      _m_a_p     The map address returned by _p_c_i_i_o__p_i_o_m_a_p__a_l_l_o_c().
  98.  
  99.      _m_a_p_p    A pointer variable to receive the address of an allocated map.
  100.  
  101.      _s_i_z_e    The size of the region to be mapped.
  102.  
  103.      _s_p_a_c_e   Specifies the target PCI address space.
  104.  
  105.      _v_h_d_l    The PCI connection point as given to the _a_t_t_a_c_h() entry point.
  106.  
  107. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  108.      When a device driver wishes to use Programmed I/O (PIO) to communicate
  109.      with a device, the system needs to have a chance to set up any
  110.      appropriate mapping registers.  The work to be done varies with the
  111.      available hardware and with the version of IRIX.  The functions described
  112.      here provide an abstract interface to the creation of PIO mapping
  113.      objects, an interface that is consistent across most hardware.  These
  114.      functions always do the least possible work given the available hardware.
  115.  
  116.      There are two models for setting up a PIO map, one simple but fallible,
  117.      and one more general.  In both models, the final goal is to retrieve a
  118.      physical address that, when used as the operand of a store or fetch, will
  119.      access a word in PCI bus address space rather than in CPU memory address
  120.      space.
  121.  
  122.    SSSSiiiimmmmpppplllleeee MMMMooooddddeeeellll
  123.      The simple model provides permanent mappings through fixed mapping
  124.      resources that may or may not exist in a given system at a given time.
  125.      _p_c_i_i_o__p_i_o_t_r_a_n_s__a_d_d_r() attempts to use shared hardware resources to
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. ppppcccciiiiiiiioooo____ppppiiiioooo((((DDDD3333))))                                                    ppppcccciiiiiiiioooo____ppppiiiioooo((((DDDD3333))))
  137.  
  138.  
  139.  
  140.      construct a physical address that, whenever used, routes the transaction
  141.      to the proper target on the PCI bus.  This is not always possible.  When
  142.      it is not, the function returns NULL.
  143.  
  144.      When it works, _p_c_i_i_o__p_i_o_t_r_a_n_s__a_d_d_r() allows the driver to do PIO with the
  145.      fewest complications.  Typically _p_c_i_i_o__p_i_o_t_r_a_n_s__a_d_d_r() always succeeds in
  146.      some platforms, and always fails in others.  However, a driver that uses
  147.      it should be coded as if it could succeed or fail alternately in the same
  148.      system (which it could).
  149.  
  150.    GGGGeeeennnneeeerrrraaaallll MMMMooooddddeeeellll
  151.      It is not always possible to establish a PIO mapping using common shared
  152.      system resources, so the concept of a PIO channel that preallocates
  153.      scarce mapping resources is provided.
  154.  
  155.      Such a channel is allocated using _p_c_i_i_o__p_i_o_m_a_p__a_l_l_o_c(), which is given
  156.      the limits of the region that will be mapped, and the maximum size to be
  157.      mapped at any time within that region.  The model assumes that many
  158.      channels may be created, but that not all channels will be actively in
  159.      use at any time.
  160.  
  161.      _p_c_i_i_o__p_i_o_m_a_p__a_d_d_r() is used to actually establish the proper mappings for
  162.      a PIO target.  Given the offset within the target address space and the
  163.      size of the region for PIO, it returns the base address to be used for
  164.      accessing that region.
  165.  
  166.      After all PIO transactions to that region are executed,
  167.      _p_c_i_i_o__p_i_o_m_a_p__d_o_n_e() should be called to idle any mapping hardware and
  168.      possibly to flush out any pipes or buffers along the path that might do
  169.      unexpected things when mapping registers are modified.
  170.  
  171.      Later, _p_c_i_i_o__p_i_o_m_a_p__a_d_d_r() can again be called, specifying the same or a
  172.      new target area.
  173.  
  174.      When a driver is completely finished with a PIO channel -- either because
  175.      the channel is used only for initialization of the device, or because the
  176.      device or the driver is being shut down -- the PIO channel resources
  177.      should be released using _p_c_i_i_o__p_i_o_m_a_p__f_r_e_e().
  178.  
  179.    UUUUttttiiiilllliiiittttyyyy FFFFuuuunnnnccccttttiiiioooonnnnssss
  180.      _p_c_i_i_o__p_i_o__a_d_d_r() is a wrapper function that calls _p_c_i_i_o__p_i_o_t_r_a_n_s__a_d_d_r()
  181.      to establish a mapping.  If that call fails, it then allocates a map
  182.      using _p_c_i_i_o__p_i_o_m_a_p__a_l_l_o_c() (or uses the preallocated map passed in via
  183.      the _m_a_p_p pointer), and fills it in using _p_c_i_i_o__p_i_o_m_a_p__a_d_d_r(), returning
  184.      the resulting piomap via the map pointer _m_a_p_p.  This function
  185.      encapsulates the common two-step process of attempting a simple address
  186.      translation and falling back to the more general process in the event the
  187.      simple approach fails.
  188.  
  189.      _p_c_i_i_o__p_i_o_s_p_a_c_e__a_l_l_o_c() can be used to find a block of PCI address space
  190.      that nobody else is using, which can then be used for whatever the device
  191.      and driver wish to use it for.  The PCI infrastructure preallocates PCI
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. ppppcccciiiiiiiioooo____ppppiiiioooo((((DDDD3333))))                                                    ppppcccciiiiiiiioooo____ppppiiiioooo((((DDDD3333))))
  203.  
  204.  
  205.  
  206.      address space regions based on the device configuration BASE registers at
  207.      the time the bus is discovered.  As a result this function is needed only
  208.      to manage a device that does not completely declare its address space
  209.      usage in its hardware configuration registers.
  210.  
  211.      _p_c_i_i_o__p_i_o_s_p_a_c_e__f_r_e_e() is used to release any allocations that were
  212.      previously made by _p_c_i_i_o__p_i_o_s_p_a_c_e__a_l_l_o_c().
  213.  
  214.    SSSSppppeeeecccciiiiffffyyyyiiiinnnngggg PPPPCCCCIIII AAAAddddddddrrrreeeessssssss SSSSppppaaaacccceeeessss
  215.      The _s_p_a_c_e parameter takes on of the following values:
  216.  
  217.      PCIIO_SPACE_WIN(n)
  218.                  specifies one of the regions on the PCI bus decoded by the
  219.                  PCI card's BASE registers.  The address specified is the
  220.                  offset within the decoded area, and the entire PIO region
  221.                  must fit within the decoded area.
  222.  
  223.      PCIIO_SPACE_CFG
  224.                  requests a pointer handle that can be used to access the
  225.                  configuration space for the card, via the _p_c_i_i_o__c_o_n_f_i_g__g_e_t()
  226.                  and _p_c_i_i_o__c_o_n_f_i_g__s_e_t() functions documented in
  227.                  pciio_config(D3).
  228.  
  229.      Other space types are rarely needed but can be used:
  230.  
  231.      PCIIO_SPACE_IO
  232.                  requests a mapping into somewhere in the PCI bus I/O address
  233.                  space.
  234.  
  235.      PCIIO_SPACE_MEM
  236.                  requests a mapping into somewhere in the PCI bus Memory
  237.                  space.  Since PCI bus address space is preallocated by the
  238.                  kernel, this is a dangerous function to use.
  239.  
  240.    PPPPIIIIOOOO AAAAttttttttrrrriiiibbbbuuuutttteeee FFFFllllaaaaggggssss
  241.      The _f_l_a_g_s argument specifies some uses of the map.
  242.  
  243.      PCIIO_FIXED states that all translations will be done using fixed shared
  244.                  resources; the results of those translations will remain
  245.                  valid permanently, even if the map resource is subsequently
  246.                  used to obtain additional mappings.
  247.  
  248.      PCIIO_NOSLEEP
  249.                  requests that any resources that are needed from the system
  250.                  are allocated without sleeping.  If any resource allocation
  251.                  would have required the infrastructure to sleep, the service
  252.                  call will return a failure code.
  253.  
  254. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  255.      Here is a contrived example of how one might initialize a very strange
  256.      PCI card.  It is not clear that this would be the best way to do it, but
  257.      it does give an example of the relationship between the various
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. ppppcccciiiiiiiioooo____ppppiiiioooo((((DDDD3333))))                                                    ppppcccciiiiiiiioooo____ppppiiiioooo((((DDDD3333))))
  269.  
  270.  
  271.  
  272.      functions.
  273.  
  274.           pcifoo_attach(vertex_hdl_t vhdl)
  275.           {
  276.                unsigned  *cfgspace;
  277.                struct pcifoo_devregs *devregs;
  278.                pciio_piomap_t pmap;
  279.                pciio_piomap_t cmap;
  280.                struct pcifoo_chan_config *tune;
  281.                ...
  282.                /* Get the configuration space base
  283.                 * pointer.
  284.                 */
  285.                cfgspace = pciio_piotrans_addr
  286.                     (vhdl, 0, PCIIO_SPACE_CFG, 0, 256, 0);
  287.                if (cfgspace == NULL) {
  288.                     cmn_err(CE_ALERT,
  289.                          "pcifoo_attach: pciio_piotrans_addr failed");
  290.                     return -1;
  291.                }
  292.                /* Get a pointer we can use for PIO to our
  293.                 * device's control registers. This call
  294.                 * attempts to use fixed shared resources,
  295.                 * but will allocate unshared mapping resources
  296.                 * if required.
  297.                 */
  298.                devregs = pciio_pio_addr
  299.                     (vhdl, 0,
  300.                     PCIIO_SPACE_WIN(0), 0,
  301.                     sizeof (struct pcifoo_devregs),
  302.                     &pmap, 0);
  303.                if (devregs == NULL) {
  304.                     cmn_err(CE_ALERT,
  305.                          "pcifoo_attach: pciio_pio_addr failed");
  306.                     return -1;
  307.                }
  308.                /* save cfgspace and devregs for use;
  309.                 * save pmap for pciio_dmamap_free
  310.                 * call if/when we are unregistered.
  311.                 */
  312.                ...
  313.                /* pretend our "channel" space is too big
  314.                 * to successfully map with piotrans, so
  315.                 * we have to use piomap, and that it is
  316.                 * too big for us to get it in one call
  317.                 * to piomap_addr.
  318.                 */
  319.                cmap = pciio_piomap_alloc(vhdl, 0,
  320.                     PCIIO_SPACE_WIN(2), 0, CHAN_SEP * CHANS,
  321.                     sizeof (struct pcifoo_chan_config), 0);
  322.                for (chan = 0; chan < chans; ++chan) {
  323.                     tune = (struct pcifoo_chan_config *)
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. ppppcccciiiiiiiioooo____ppppiiiioooo((((DDDD3333))))                                                    ppppcccciiiiiiiioooo____ppppiiiioooo((((DDDD3333))))
  335.  
  336.  
  337.  
  338.                     pciio_piomap_addr(cmap, CHAN_SEP * chan,
  339.                               sizeof (struct pcifoo_chan_config));
  340.                     /* now fiddle with this particular channel */
  341.                     tune->chan = chan + 2;
  342.                     tune->volume = 5;
  343.                     tune->balance = 0;
  344.                     pciio_piomap_done(cmap);
  345.                }
  346.                pciio_piomap_free(cmap);
  347.                ...
  348.           }
  349.  
  350.  
  351. NNNNOOOOTTTTEEEESSSS
  352.      Do not point the _m_a_p_p parameter to the _p_c_i_i_o__p_i_o__a_d_d_r() function at your
  353.      only copy of a map pointer, since it will write a NULL through this
  354.      pointer when direct translations work.
  355.  
  356.      It is not necessary to separately establish mappings for each individual
  357.      PIO target register.  It is customary and more efficient to use a single
  358.      mapping to cover the entire register set of a device.
  359.  
  360. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  361.      pciio(D3), pciio_config(D3), pciio_dma(D3), pciio_error(D3),
  362.      pciio_get(D3), pciio_intr(D3).
  363.  
  364. DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  365.      _p_c_i_i_o__p_i_o_t_r_a_n_s__a_d_d_r() returns a null pointer when shared (fixed)
  366.      resources can not be used to construct a valid physical address that maps
  367.      to the desired range of PCI addresses.
  368.  
  369.      _p_c_i_i_o__p_i_o__a_d_d_r() returns a null pointer when the target PCI address can
  370.      not be mapped either with shared (fixed) resources, or with unshared
  371.      mapping resources.  If this happens, and the object being mapped is
  372.      large, it might be possible to set up mappings to smaller regions of the
  373.      target space.
  374.  
  375.      _p_c_i_i_o__p_i_o_m_a_p__a_l_l_o_c() returns a null pointer when resources can not be
  376.      allocated to establish PIO mappings to the described region, or if the
  377.      function parameters are inconsistent.
  378.  
  379.      _p_c_i_i_o__p_i_o_m_a_p__a_d_d_r() returns a null pointer when the specified target
  380.      address can not be mapped using the specified PIO channel.  This would
  381.      usually be due to specifying a target block that is outside the
  382.      previously specified target area or is larger than the previously
  383.      specified maximum mapping size.  It may also return a null pointer if the
  384.      PIO channel is currently in use and has not been marked idle by a
  385.      _p_c_i_i_o__p_i_o_m_a_p__d_o_n_e() call.
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.